package com.ruoyi.web.core.config;

import com.ruoyi.by.health.domain.entity.ByhealthEmployee;
import com.ruoyi.by.health.service.IByhealthEmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class EmpInfoInitConfig {
    @Autowired
    IByhealthEmployeeService employeeService;
    @Resource
    RedisTemplate<String, Object> redisTemplate;
    private static final Logger log = LoggerFactory.getLogger(EmpInfoInitConfig.class);

    @PostConstruct
    public void initGameScoreRegion() {

        log.info("----开始初始化员工信息到redis-----");
        ByhealthEmployee employeeQo = new ByhealthEmployee();
        List<ByhealthEmployee> byhealthEmployees = employeeService.selectEmployeeList(employeeQo);
        ListOperations<String, Object> listOperations = redisTemplate.opsForList();
        for (ByhealthEmployee employee : byhealthEmployees) {
            //listOperations.leftPush("emp_list", employee);
            redisTemplate.opsForValue().set("emp_info-"+employee.getEmpId(), employee);
        }
        log.info("----初始化员工信息到redis完成-----");
    }

}
